Module-level declarations

Types

Link copied to clipboard

Allows to discern what was the last action on an account_creation_transfer.

This differs from pending_transfer_expiration_state in multiple ways. A pending_transfer_expiration_state:

  • is passed by the user in queries, to filter results

  • refers to a transfer, meaning:

    • it happened recently enough

    • it happened too long ago

On the other hand, an account_creation_state:

  • is used without user input

  • is attached to account_creation_transfer, meaning:

    • the account was registered

    • the account was not registered in time, and the transfer has been recalled

    • neither of the above has happened, awaiting input.

Thus, for a certain transfer, the pending_transfer_expiration_state can be expired, while the account_creation_state can be pending if the sender did not claim their assets back.

Additionally, since an account_creation_transfer has multiple rules associated with it, the same transfer can be considered pending for one rule and expired for another, if their timeout_days values differ.

Link copied to clipboard

Represents a transfer that had a non-existing recipient, for which at least one rule was found that allowed account registration.

Link copied to clipboard
struct allowlist

Represents a list of allowed values. Used by rules to represent allowed senders, recipients, assets, and blockchain senders.

Link copied to clipboard

Represents an asset's lower limit, below which a transfer is deemed not sufficient for account registration. This struct must contain either of these options:

  • id

  • name and blockchain_rid

If id and name are missing or both present, functions using this struct will consider it invalid.

If this value is being parsed from a GTV and name is present instead of id, blockchain_rid is optional. If missing, its value will be this chain's RID.

Link copied to clipboard
struct fee_asset

Represents an asset that will be paid for a new account registration This struct must contain either of these options:

  • id

  • name and blockchain_rid

If id and name are missing or both present, functions using this struct will consider it invalid.

If this value is being parsed from a GTV and name is present instead of id, blockchain_rid is optional. If missing, its value will be this chain's RID.

Link copied to clipboard

The configuration defined in the chromia.yml file.

Link copied to clipboard

The module_args for this module accept a list of multiple entries. This represents one of the entries, which define which transfers can be accepted to allow users to register new accounts. This is called a transfer registration rule, and when parsed will be represented by the struct rule.

A transfer must satisfy all the requirements of a single rule to be accepted.

Link copied to clipboard

Status of a transfer that was made to a non-existing account for its creation.

Link copied to clipboard

When querying for pending transfers, this can be used to filter responses.

Link copied to clipboard
struct rule

A set of requirements to be satisfied to register an account.

Properties

Link copied to clipboard
val _CONFIG_ERROR_TEXT: text = "CONFIG ERROR: Error in moduleArgs (lib.ft4.core.accounts.strategy.transfer): "

A starting string for configuration errors

Link copied to clipboard
val _CONFIG_ERROR_TEXT_TEMPLATE: text = "CONFIG ERROR: Error in moduleArgs (%s): %s"

A starting string for configuration errors in strategies using payments

Link copied to clipboard
val ACCOUNT_TYPE_FEE: text = "FT4_FEE"

Constant that represent the account type used to store fees charged during account registration. Currently used for both fee and subscription strategies.

Link copied to clipboard
val ACCOUNT_TYPE_POOL: text = "FT4_POOL"

Constant that represents the account type used to temporarily store assets of transfers that have recipient_id that does not exist, while waiting for the account registration to happen

Link copied to clipboard
val ANY_REF: text = "*"

Used in transfer strategy rules to specify that any value is accepted. All accounts, blockchains or assets (depending on the field this is found in) will be allowed for that rule.

Link copied to clipboard

Used in transfer strategy rules to specify current account for the scenario when transfer rule requires that sender and recipient is the same.

Link copied to clipboard

Used in transfer strategy rules config to specify current chain

Functions

Link copied to clipboard
function collect_pooled_assets(account: account, recipient_id: byte_array)

Moves the assets from the pool account where they were stored to the newly registered account. Marks the account_creation_transfers as done. Does not check if the rules for any strategy have been satisfied.

Can only be called from an operation.

Throws if the transfer cannot be made. Common cases include:

  • the funds are not in the pool account

  • an account with ID equal to this blockchain's pool account ID exists, but is not a pool account

Link copied to clipboard
function do_transfer(account: account, strategy: text)

Sends all assets that were sent to the pool account for a registration to the actual account that is being registered. Marks the account_creation_transfers as done. At least one of those transfers must satisfy strategy, otherwise this function will throw. Multiple transfers cannot be bundled together to reach the threshold.

Can only be called from an operation.

Throws "MISSING TRANSFER" if no account_creation_transfer is found for this account.

Throws "REGISTRATION ERROR" if none of the transfers satisfied the rule.

Throws if the transfer cannot be made. Common cases include:

  • the funds are not in the pool account anymore

  • an account with this blockchain's pool account ID exists, but is not a pool account

Link copied to clipboard
function ensure_chain_fee_account(custom_account_id: byte_array?): account

Returns the fee account for this chain, creating it if needed.

Can only be called from an operation.

Throws if custom_account_id is not null, but the account specified does not exist.

Link copied to clipboard

Returns the pool account for this chain, creating it if needed.

Can only be called from an operation.

Link copied to clipboard
function ensure_fee_account(custom_account_id: byte_array?, blockchain_rid: byte_array): account

Returns the fee account for a chain, creating it if needed. This function should not normally be used, ensure_chain_fee_account should be preferred.

Can only be called from an operation.

Throws if custom_account_id is not null, but the account specified does not exist.

Link copied to clipboard
function ensure_pool_account(blockchain_rid: byte_array): account

Returns the pool account for a chain, creating it if needed. This function should not normally be used, ensure_chain_pool_account should be preferred.

Can only be called from an operation.

Link copied to clipboard

Utility for get_pending_transfer_strategies. Returns whether an account_creation_transfer matches a specific expiration state or not.

Link copied to clipboard
function find_allowed_assets(sender_blockchain_rid: byte_array, sender_id: byte_array, recipient_id: byte_array): map<byte_array, big_integer>?

Finds all assets that a certain sender on a certain chain can send to the specified account ID to allow its registration.

This function can return that no asset is allowed. This means:

  • no rule allows account registration for the specified combination of parameters; or

  • a rule that allows this specific registration is found, but the asset that it requires is not yet registered on this chain.

Link copied to clipboard
function find_allowed_rules(from_chain: byte_array, from_id: byte_array, to_id: byte_array, asset: asset, amount: big_integer): map<text, rule>

Returns all rules on this chain that can be used to register an account given the parameters of the transfer.

Link copied to clipboard
Link copied to clipboard
@extend(create_on_internal_transfer) function (sender: account, recipient_id: byte_array, asset: asset, amount: big_integer)
Link copied to clipboard
@extend(recall_on_internal_transfer) function (sender: account, transfer_tx_rid: byte_array, transfer_op_index: integer)
Link copied to clipboard
Link copied to clipboard
@extend(create_on_crosschain_transfer) function (sender_blockchain_rid: byte_array, sender_id: byte_array, recipient_id: byte_array, asset: asset, amount: big_integer)
Link copied to clipboard
@extend(recall_on_crosschain_transfer) function (sender_blockchain_rid: byte_array, sender_id: byte_array, transfer_tx_rid: byte_array, transfer_op_index: integer)
Link copied to clipboard
@extend(after_register_account) function (account: account)
Link copied to clipboard
function get_config(config_gtv: gtv): list<rule>

Retrieves all rules following which a transfer can be used to register a new account.

Throws "CONFIG ERROR" if the config cannot be parsed. Common cases are:

  • CURRENT_ACCOUNT_REF is used in exactly one of sender or recipient

  • timeout_days is a negative number

  • sender or recipient have a list of values, alongside which CURRENT_ACCOUNT_REF or ANY_REF are found

  • some fields contain unexpected values. For example:

    • IDs cannot be parsed as hex byte_arrays

    • asset limits are invalid

Throws if any field is improperly formatted, in such a way that the values cannot be parsed.

Link copied to clipboard

Checks whether the transfer has timed out. This means the transfer would have satisfied a certain rule but timeout_days has elapsed.

Link copied to clipboard
function has_tx_expired(rule: rule, tx_start_timestamp: integer): boolean

Utility function which returns whether a transaction has expired, given the rule it was using to register the account. If a transaction has expired, the account can no longer be registered and the transfer can be recalled to move funds back to the original sender.

Link copied to clipboard
function is_asset_amount_allowed(rule: rule, asset: asset, amount: big_integer): boolean

Utility function which returns whether a rule allows a certain amount of an asset to be sent to register new accounts.

Link copied to clipboard
function is_blockchain_allowed(rule: rule, blockchain_rid: byte_array): boolean

Utility function which returns whether a rule allows a certain blockchain_rid as sender.

Link copied to clipboard
function is_recipient_allowed(rule: rule, recipient_id: byte_array, sender_id: byte_array): boolean

Utility function which returns whether a rule allows a certain account ID as recipient. Since some rules allow all recipients as long as the sender is the same as the recipient, the sender ID is needed as well.

Link copied to clipboard
function is_sender_allowed(rule: rule, sender_id: byte_array): boolean

Utility function which returns whether a rule allows a certain account ID as sender.

Link copied to clipboard
function is_strategy_active(rule: rule, strategy: text): boolean

Utility function which returns whether a rule allows a certain registration strategy.

Link copied to clipboard
function is_value_allowed(value: byte_array, allowlist: allowlist): boolean

Utility function which returns whether a value is allowed by a certain allowlist. This means the allowlist is either set to allow all values, or the value is specified in the list of allowed values.

Link copied to clipboard

Reads a GTV-encoded moduleArgs field containing a single account ID.

Throws "CONFIG ERROR" if the ID cannot be parsed as hex byte_array

Link copied to clipboard
function parse_account_ids_from_gtv(gtv: gtv): (allowlist: allowlist, require_same: boolean)

Reads a GTV-encoded moduleArgs field containing account IDs.

Throws "CONFIG ERROR" if the config cannot be parsed. Common cases are:

  • a list of values is received, alongside which CURRENT_ACCOUNT_REF or ANY_REF are found

  • IDs cannot be parsed as hex byte_arrays

Link copied to clipboard
function parse_amount(input: gtv): big_integer

Reads a GTV-encoded moduleArgs field containing asset limits.

Link copied to clipboard

Reads a moduleArgs field containing a single asset limit, structured like a dictionary.

Throws "CONFIG ERROR" if the asset limits are invalid.

Link copied to clipboard

Reads a GTV-encoded moduleArgs field containing asset limits.

Throws "CONFIG ERROR" if the asset limits are invalid.

Throws if the asset limits are improperly formatted.

Link copied to clipboard

Reads a GTV-encoded moduleArgs field containing a single blockchain RID.

Throws "CONFIG ERROR" if the RID cannot be parsed as hex byte_array

Link copied to clipboard

Reads a GTV-encoded moduleArgs field containing blockchain RIDs.

Throws "CONFIG ERROR" if the config cannot be parsed. Common cases are:

  • a list of values is received, alongside which ANY_REF are found

  • IDs cannot be parsed as hex byte_arrays

Link copied to clipboard
function parse_fee_asset(input: map<text, gtv>, module_name: text): fee_asset

Parses a dictionary retrieved from the module_args of a module and returns the corresponding fee_asset.

Throws "CONFIG ERROR" if the fee_asset is invalid.

Link copied to clipboard
function parse_fee_assets(gtv: gtv, module_name: text): list<fee_asset>

Parses the module_args for a module, where the value contained is a list of fee_assets.

Throws "CONFIG ERROR" if gtv is neither a dictionary nor a list of dictionaries.

Throws if any of the assets is not a valid fee_asset.

Link copied to clipboard
function pool_assets(sender_blockchain_rid: byte_array, sender_id: byte_array, recipient_id: byte_array, asset: asset, amount: big_integer)

This method ensures that a rule exists for the transfer defined by the parameters passed, and creates an account_creation_transfer entity representing that transfer.

This function does not check that the account does not exist, assuming it has been checked before calling this.

This function does not allow multiple transfers of the same asset to be transferred to the same account, regardless of sender.

Can only be called from an operation.

Throws "TRANSFER NOT ALLOWED" if:

  • no rule allows that transfer, or

  • a pending transfer to the same account ID with the same asset already exists

Link copied to clipboard
function pool_assets_with_rules(sender_blockchain_rid: byte_array, sender_id: byte_array, recipient_id: byte_array, asset: asset, amount: big_integer, rules: map<text, rule>): account_creation_transfer

Creates an account_creation_transfer entity given its parameters.

Can only be called from an operation.

This function does not check anything. It simply creates the entity, so exceptional care is required if this function is needed. Although this function is provided, it is intended for internal use - no use-case should really require it.

Link copied to clipboard
function recall_transfer(sender_blockchain_rid: byte_array, sender_id: byte_array, transfer_tx_rid: byte_array, transfer_op_index: integer): (asset, big_integer)

Marks a specific account_creation_transfer that has expired as recalled. It does not send the assets back to the sender.

Can only be called from an operation.

Throws "RECALL ERROR" if the transfer cannot be recalled. Common cases include:

  • no pending transfer is found with the specified details:

    • the transfer was already completed or recalled

    • the transfer was never created

  • too many transfers have the specified details. This should never happen, but it could be caused by one operation creating multiple account_creation_transfers

  • the transfer was found, but it has not yet timed out

Link copied to clipboard

Finds all assets that a certain rule allows for account registration.

Link copied to clipboard

Parses a list of fee_assets, and returns a map of all the ones that could be mapped to actual assets. This does not throw if an asset has not yet been registered, allowing assets to be added to the config a long time before actually registering them.

This function does not discern when a fee_asset entry is invalid. This is because it will typically be called after the fee_asset has been parsed and values have been fixed when possible. If improper input is provided, this function will behave this way:

  • if id is present, other values will be ignored

  • if id is missing, name and blockchain_rid must both be present - it will throw otherwise

Queries

Link copied to clipboard
@mount("ft4.get_allowed_assets") query get_allowed_assets(sender_blockchain_rid: byte_array, sender_id: byte_array, recipient_id: byte_array): list<(asset_id: byte_array, min_amount: big_integer)>?

Retrieves a list of assets that are allowed for account creation on this chain, given the parameters of the transfer that is going to register one.

Link copied to clipboard
@mount("ft4.get_pending_transfer_strategies") query get_pending_transfer_strategies(recipient_id: byte_array, filter: pending_transfer_filter?): set<text>

Retrieves all account_creation_transfers that are pending (that is, not recalled nor completed), optionally filtering them based on whether they expired or not.

Link copied to clipboard
@mount("ft4.get_transfer_rules") query get_transfer_rules(): list<rule>

Returns a list of rules representing all conditions under which assets can be transferred to register a new account. For a transaction to be allowed, it must fulfill all criteria for at least one of the rules.

Throws if any rule found in the chromia.yml is misconfigured. Common cases of misconfiguration can be found on the API docs for get_config

@mount("ft4.has_pending_create_account_transfer_for_strategy") query has_pending_create_account_transfer_for_strategy(strategy_name: text, sender_blockchain_rid: byte_array, sender_id: byte_array, recipient_id: byte_array, asset_id: byte_array, amount: big_integer): boolean

Returns whether a certain pending account_creation_transfer exists, which means that a certain sender has sent the specified amount of this asset and the recipient has not yet created that account.